package com.handler.product;

import com.dao.mapper.Product;
import com.handler.exception.ProductException;
import com.service.product.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/product")
@Controller
public class ProductController {

    @RequestMapping(value = "/recent",method = RequestMethod.GET)
    public @ResponseBody List<Product> getAll() throws ProductException {
        List<Product> result = ProductService.getAll();
        if(result == null){
            throw new ProductException();
        }
        return result;
    }

    @RequestMapping(value = "{id}",method = RequestMethod.GET)
    public @ResponseBody Product getOne(@PathVariable Integer id) throws ProductException {
        Product result = ProductService.getOne(id);
        if(result == null){
            throw new ProductException();
        }
        return result;
    }
}
